package com.jcark.arch.net.utils

import android.content.Context
import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.util.Log
import java.util.*

object PackageUtils {
    internal val TAG = PackageUtils::class.java.simpleName

    /**
     * 通过报名获取包信息
     */
    fun getPackageInfoByName(context: Context, packageName: String?): PackageInfo? {
        return if (null == packageName || "" == packageName) {
            null
        } else try {
            context.packageManager.getPackageInfo(
                packageName,
                PackageManager.GET_META_DATA or PackageManager.GET_SHARED_LIBRARY_FILES
            )
        } catch (e: PackageManager.NameNotFoundException) {
            Log.e("PackageUtils", e.localizedMessage)
            null
        }
    }

}